package com.gene.controller.order;


import com.gene.pojo.entity.Indent;
import com.gene.pojo.entity.Order;
import com.gene.service.ITbOrderService;
import com.gene.utils.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 订单类
 */
@Controller
@RequestMapping("/gene-safe/order")
public class TbOrderController {
    @Autowired
    private ITbOrderService tbOrderService;


    /**
     * 查询 一般查询条件为orderId(订单id)   userId(用户id)
     * @param order
     * @return
     */
    @RequestMapping(value="/query")
    @ResponseBody
    public ResultData query(Order order){
        ResultData result=new ResultData();
        List<Order> list=tbOrderService.query(order);
        if(list.size()!=0){
            result.setData(list);
            result.setStatus("1");
            result.setMsg("查询成功！");
        }else{
            result.setStatus("0");
            result.setMsg("没有数据！");
        }

        return result;
    }


    /**
     * 新增(新)
     * @param indent
     * @return
     */
    @RequestMapping(value="/addPage")
    @ResponseBody
    public ResultData addPage(Indent indent){
        ResultData result=new ResultData();
        boolean a=tbOrderService.addPage(indent);
        if(a){
            result.setStatus("1");
            result.setMsg("新增成功...");
        }else{
            result.setStatus("0");
            result.setMsg("新增失败！");
        }
        return result;
    }


    /**
     * 新增
     * @param order
     * @return
     */
    @RequestMapping(value="/add")
    @ResponseBody
    public ResultData add(Order order){
        ResultData result=new ResultData();
        boolean a=tbOrderService.add(order);
        if(a){
            result.setStatus("1");
            result.setMsg("新增成功...");
        }else{
            result.setStatus("0");
            result.setMsg("新增失败！");
        }
        return result;
    }

    /**
     * 修改页面
     * @param order
     * @return
     */
    @RequestMapping(value="/edit")
    @ResponseBody
    public ResultData edit(Order order) {
        ResultData result = new ResultData();
        boolean a=tbOrderService.edit(order);
        if(a){
            result.setStatus("1");
            result.setMsg("修改成功...");
        }else{
            result.setStatus("0");
            result.setMsg("修改失败！");
        }
        return result;
    }

    @RequestMapping(value="/delete")
    @ResponseBody
    public ResultData delete(Order order) {
        ResultData result = new ResultData();
        boolean a=tbOrderService.delete(order);
        if(a){
            result.setStatus("1");
            result.setMsg("删除成功...");
        }else{
            result.setStatus("0");
            result.setMsg("删除失败！");
        }
        return result;
    }

    /**
     * 根据userId 、status查询出所有待付款订单 status=(1、待付款；2、待发货；3、待收货；4、已完成)
     * @param order
     * @return
     */
    @RequestMapping(value="/await")
    @ResponseBody
    public ResultData await(Order order){
        ResultData result=new ResultData();
        List<Order> list = tbOrderService.await(order);

        if(list.size()!=0){
            result.setData(list);
            result.setStatus("1");
            result.setMsg("查询成功！");
        }else{
            result.setStatus("0");
            result.setMsg("没有数据！");
        }
        return result;
    }
}
